#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from error import *

class Arbol:
    pass

class ArbolEntero(Arbol):
    def __init__(self, valor):
        self.valor = valor
        
    def evalua(self):
        return self.valor.valor
    
    def __str__(self):
        return str(self.valor)
    
    def imprimeAST(self, nivel):
        return ("\t" + "|") * nivel + "Entero: %d\n" % self.valor.valor
    
    
class ArbolSuma(Arbol):
    def __init__(self, izq, der):
        self.izq = izq
        self.der = der
        
    def evalua(self):
        return self.izq.evalua() + self.der.evalua()
    
    def __str__(self):
        return "(%s + %s)" % (self.izq, self.der)
    
    def imprimeAST(self, nivel):
        salida = self.izq.imprimeAST(nivel + 1)
        salida = salida + ("\t" + "|") * nivel + "Suma"
        salida = salida + self.der.imprimeAST(nivel + 1)
        return salida
        
class ArbolProducto(Arbol):
    def __init__(self, izq, der):
        self.izq = izq
        self.der = der
        
    def evalua(self):
        return self.izq.evalua() * self.der.evalua()
    
    def imprimeAST(self, nivel):
        salida = self.izq.imprimeAST(nivel + 1)
        salida = salida + ("\t" + "|") * nivel + "Producto"
        salida = salida + self.der.imprimeAST(nivel + 1)
        return salida
        
